package data;

import java.sql.SQLException;

import bdd.ConnectionOracle;

public class Login {
    private Object login = "invite";
    private Object password = "invite";
    private ConnectionOracle connection = new ConnectionOracle();

    public void set(Object login, Object password) {
	this.setLogin(login);
	this.setPassword(password);
    }

    public Object getLogin() {
	return this.login;
    }

    public Object setLogin(Object login) {
	this.login = ((String) login).toLowerCase();
	return this.getLogin();
    }

    public Object getPassword() {
	return password;
    }

    public Object setPassword(Object password) {
	this.password = password;
	return this.getPassword();
    }

    public boolean connect() {
	try {
	    if (!connection.isNull())
		connection.dropInstance();
	    connection.getInstance(this);
	    return true;
	} catch (SQLException e) {
	    try {
		this.setLogin("invite");
		this.setPassword("invite");
		connection.getInstance(this);
	    } catch (SQLException e1) {
		e1.printStackTrace();
	    }
	    return false;
	}
    }

    @Override
    public String toString() {
	return this.getLogin().toString();
    }

    @Override
    public boolean equals(Object obj) {
	if (this.toString().equals(obj))
	    return true;
	return false;
    }
}
